﻿using System;
using System.Linq.Expressions;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;

namespace SBACN.WebSite
{
    public partial class MediaList : MemberBasePage
    {
        public int PageFlag { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindData(1); 
        }


        protected void BindData(int pageIndex)
        {
            string id = Request.QueryString["id"];
            if (!string.IsNullOrEmpty(id))
            {
                this.PageFlag = (pageIndex - 1) * this.Pager1.PageSize;
                int records = 0;
                int iid = int.Parse(id);
                Expression<Func<TB_MediaReports, bool>> f = (p => p.ActivityID == iid);
                Expression<Func<TB_MediaReports, DateTime>> order = (c => c.ReportDate);
                var resultQ = DAL.DALHelper.Instance.GetList<TB_MediaReports, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);

                if (resultQ != null && resultQ.Count > 0)
                {
                    this.List.DataSource = resultQ;
                    this.List.DataBind();
                    this.Pager1.RecordCount = records;
                    this.Pager1.InitControl();
                }
                else
                {
                    List.Visible = false;
                }
            }
        }
        protected void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
        {
            BindData(nextPage);
        }
    }
}